﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FacebookAPI.Base;
using FacebookAPI.FacebookProperties;
using FacebookAPI.Objects;

namespace FacebookAPI.Managers
{
    public class FriendListManager
    {
        public string CreateFriendList(string ownerObjectId, string friendListName, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            FriendList friendList = new FriendList() { Name = friendListName };
            FacebookBaseObject response = mgr.SaveObject<FacebookBaseObject>(mgr.GetUrl(ownerObjectId, FacebookConnections.FriendLists, accessToken), friendList.GetPostData());
            return (response != null) ? response.Id : string.Empty;
        }

        public FacebookConnection<FriendList> GetFriendsLists(string ownerObjectId, List<string> fields, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            FacebookQueryField field = new FacebookQueryField()
            {
                FieldName = "Fields",
                FieldValues = fields
            };
            return mgr.GetConnectionObject<FriendList>(mgr.GetUrl(ownerObjectId, FacebookConnections.FriendLists, field, null, accessToken, false));
        }

        public bool DeleteFriendList(string friendListId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.DeleteObject<bool>(mgr.GetUrl(friendListId, null, accessToken));
        }

        public bool AddMember(string friendListId, string memberId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.SaveObject<bool>(mgr.GetUrl(friendListId + "/members/" + memberId, null, accessToken));
        }

        public bool DeleteMember(string friendListId, string memberId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.DeleteObject<bool>(mgr.GetUrl(friendListId + "/members/" + memberId, null, accessToken));
        }

        public FacebookConnection<FacebookBaseObject> GetFriendListMembers(string friendListId, string accessToken)
        {
            FacebookManager mgr = new FacebookManager();
            return mgr.GetConnectionObject<FacebookBaseObject>(mgr.GetUrl(friendListId, FacebookConnections.Members, accessToken));
        }
    }
}
